/*
**NCS message communication between the ncs's processs including
**ncs client and ncs serv.
**This module provide the head files of processing the message
**It receives the ncs client's messages,or send messages to ncs
**client process.It uses the unix socket to finish this functions.
**
**Copyright (C) 2016-1 andisat <www.andisat.com>
**
**Author: andisat
**Date:2016-1
**
*/
#ifndef __NCS_MESSAGE__
#define __NCS_MESSAGE__

#include "ncs_serv.h"
#include "ncs_dev.h"


#define BUFF_MAX    1500
#define MSG_HEAD_LEN 3
#define TLV_HEAD_LEN 3

enum CFGMSG_FLAG_ENUM{
    CFG_FLAG_NULL=0,
    CFG_FLAG_ADD=0X01,
    CFG_FLAG_DEL=0X02,
    CFG_FLAG_UPDATE=0X04,
    CFG_FLAG_ID=0X08,
    CFG_FLAG_CLEAR=0X10,
    CFG_FLAG_MAX=0X10
};

enum NCS_CLIENT_MSG_ENUM{
    __NCS_CLIENT_MSGTYPE_NULL__=0,
    __NCS2NMS_RDCFG_FINISH_MSG__,
    __NCS2NMS_REPORT_MSG__,
    __NCS2NMS_CFGRESULT_REPORT_MSG__,
    __NCS2NMS_LOGON_MSG__,
    __NMS2NCS_LOGOFF_MSG__,
    __NMS2NCS_DEVCFG_MSG__,
    __NMS2NCS_CARRIERLOCK_MSG__,
    __NMS2NCS_CARRIERLOCK_RELEASE_MSG__,
    __NMS2NCS_RELEASE_RESOURCE_MSG__,
    __NCS_CLIENT_MSGTYPE_MAX__,
};

struct msg_hdr{
    char type;
    short len;
};

struct carrierLock_msg{
    int rxdevId;
    char rxchaId;
    int txdevId;
    char txchaId;
    int Freq;
    int BandWidth;
};

struct cfgmsg_hdr{
    char devType;
    int devId;
    int cnt;
};

struct cfgmsg{
    char type;
    char flag;
    int rc_id;
};

struct logoffmsg{
    int devID;
    char chaID;
};

struct ncs_client_msg_func{
	char msgtype;
	int (*func)(char type,void *arg,void *buff);
};

typedef  int (*MSG_FUNC)(char type,void *arg,void *buff);

/*declaration functions*/
int ncs_creat_client_un(struct ncs_object *ncs);
int ncs_send_rdcfg_finish_msg(int fd);
int ncs_logon_msg(char type,void *arg,void *buff);
int ncs_logoff_rcst_msg(char type,void *arg,void *buff);
int ncs_devcfg_msg(char type,void *arg,void *buff);
int ncs_carrierlock_msg(char type,void *arg,void *buff);
int ncs_carrierlock_rel_msg(char type,void *arg,void *buff);
int ncs_rel_resource_msg(char type,void *arg,void *buff);
int sig_cfg_process(struct ncs_object *ncs,int devId,char *pinfo,int cnt);
int rx_cfg_process(struct ncs_object *ncs,int devId,char *pinfo,int cnt);
int rcst_cfg_process(struct ncs_object *ncs,int devId,char *pinfo,int cnt);
void ncs_client_recv(int fd,short event,void *arg);
int ncs2nms_send_report_msg(int fd,char *buff,int bytes);
int pp_updatepars(struct ncs_object *ncs,struct dev_obj *pp,void *arg,int cnt);
int modem_updatepars(struct ncs_object *ncs,struct dev_obj *dev,void *arg,int cnt);
int ncs_msg_add(struct list *tlvList, int devID, char devType, char *outBuffer, short *pLength);
int ncs_msg_logoff(struct list *tlvList, int devID, char chaID, char *outBuffer, short *pLength);
void ncs2nms_report_devstate(struct dev_obj *dev);
void ncs_get_cfginfo_from_db(struct ncs_object *ncs);
void ncs_get_dev_from_db(struct ncs_object *ncs);

#endif

